package com.bing.controller.front;

import com.bing.bean.weixin.Article;
import com.bing.services.NewService;
import com.bing.utils.ScriptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Administrator on 2015/7/5.
 */

@RequestMapping("news")
@Controller
public class NewsController {

    @Autowired
    private NewService newService;

    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    public ModelAndView news(@PathVariable("id") int id) {
        ModelAndView modelAndView = new ModelAndView("front/news");
        Article article = newService.findById(id);
        article.setContent(ScriptUtils.md2Html(article.getContent()));
        article.setDu(article.getDu() + 1);
        newService.updateNew(article);
        modelAndView.addObject("new", article);
        return modelAndView;
    }
}
